﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
namespace WebClient.admin.Modules.userGroups
{
    public partial class Edit : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
            if (!this.IsPostBack)
            {
                InitItem();
            }
        }

        private void AddNew()
        {
            WebData data = new WebData();
            Usergroups item = new Usergroups();
            item.id = Convert.ToInt32(this.txtid.Text.Trim());
            item.groupName = this.txtgroupName.Text.Trim();
            item.description = this.txtdescription.Text.Trim();
            item.isActive = Convert.ToInt32(this.txtisActive.Text.Trim());
            data.OnSubmitUsergroups(item, 1);
        }
        private void InitItem()
        {
            //ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
            WebData db = new WebData();
            Usergroups item = new Usergroups();
            object id = 6;
            String str= Request.Params["ID1"];
            if (str != null) {
                id = Convert.ToInt32(str);
            }

            item = db.GetItemByIdUsergroups(id);
            if (item != null)
            {
                txtid.Text = item.id.ToString();
                txtgroupName.Text = item.groupName.ToString();
                txtdescription.Text = item.description.ToString();
                txtisActive.Text = item.isActive.ToString();
            }

        }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            AddNew();
        }
    }
}